﻿using System.Collections.Generic;
using System.Linq;
using studentSubsidy.Dao;
using studentSubsidy.Entity.Home;
using studentSubsidy.Entity;
using studentSubsidy.Models;
using studentSubsidy.Utils;
using Result = studentSubsidy.Entity.Result;

namespace studentSubsidy.Service
{
    public class HomeService
    {
        private HomeDao _homeDao = new HomeDao();

        public Result GetCarousel()
        {
            List<Picture> carouselReturns = _homeDao.getCarousel();
            return new Entity.Result(200, "搜索成功", carouselReturns, 0);
        }

        public Result GetProjectByCategory(int category_id_query)
        {
            List<Project> projectReturns = _homeDao.getProjectByCategory(category_id_query);
            return new Result(200, "搜索成功", projectReturns, 0);
        }

        public Result GetCategory()
        {
            List<CategoryReturn> categoryList = new List<CategoryReturn>();
            CategoryReturn categoryReturn1 = new CategoryReturn(1, "奖学金", "reward");
            CategoryReturn categoryReturn2 = new CategoryReturn(2, "助学金", "loans");
            categoryList.Add(categoryReturn1);
            categoryList.Add(categoryReturn2);
            return new Result(200, "搜索成功", categoryList, null);
        }

        public Result GetAllProject(ProjectQuery projectQuery)
        {
            List<Project> projects = _homeDao.getAllProject();
            List<Project> projectsReturn = PageHelper.PageStart(projectQuery.currentPage, projectQuery.pageSize, projects.Count, projects);
            return new Result(200, "搜索成功", projectsReturn, projects.Count);
        }

        public Result GetProjectByCategoryPage(ProjectQuery projectQuery)
        {
            List<Project> projects = _homeDao.getProjectByCategoryPage(projectQuery);
            List<Project> projectsReturn = PageHelper.PageStart(projectQuery.currentPage, projectQuery.pageSize, projects.Count, projects);
            return new Result(200, "搜索成功", projectsReturn, projects.Count);
        }
    }
}